<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>锋迷网-订单管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/bootstrap.min.css">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function sendOrder(id) {
            location.href = "${pageContext.request.contextPath}/sendOrder?oid=" + id;
        }

        $(function () {
            $("#search").click(function () {
                var username = $("input[name='username']").val();
                var status = $("select[name='orderStatus'] option:selected").val();
                location.href = "${pageContext.request.contextPath}/selectOrderByNameAndFlag?&username=" + username + "&status=" + status;
            })
        })

        function firstPage(page,username,status) {
            $("#first").click(function () {
                this.href = "${pageContext.request.contextPath}/selectOrderByNameAndFlag?page=" + page + "&username=" + username + "&status=" + status;
            })
        }

        function prePage(page,username,status) {
            $("#pre").click(function () {
                this.href= "${pageContext.request.contextPath}/selectOrderByNameAndFlag?page=" + page + "&username=" + username + "&status=" + status;
            })
        }

        function nextPage(page,username,status) {
            $("#next").click(function () {
                this.href = "${pageContext.request.contextPath}/selectOrderByNameAndFlag?page=" + page + "&username=" + username + "&status=" + status;
            })
        }

        function lastPage(page,username,status) {
            $("#last").click(function () {
                this.href = "${pageContext.request.contextPath}/selectOrderByNameAndFlag?page=" + page + "&username=" + username + "&status=" + status;
            })
        }
    </script>
</head>
<body>
<div class="row" style="width:100%;margin-left: 1%;margin-top: 5px;">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <div class="panel-body">
            <div class="row">
                <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
                    <div class="form-group form-inline">
                        <span>用户姓名</span>
                        <input type="text" name="username" class="form-control">
                    </div>
                </div>
                <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
                    <div class="form-group form-inline">
                        <span>订单状态</span>
                        <select name="orderStatus" class="form-control">
                            <option value="0">----------</option>
                            <option value="1">未支付</option>
                            <option value="2">已支付,待发货</option>
                            <option value="3">已发货,待收货</option>
                            <option value="4">已收货,未评价</option>
                            <option value="5">完成订单</option>
                        </select>
                    </div>
                </div>
                <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
                    <button type="button" class="btn btn-primary" id="search"><span
                            class="glyphicon glyphicon-search"></span></button>
                </div>
            </div>
            <table id="tb_list" class="table table-striped table-hover table-bordered">
                <tr>
                    <td>序号</td>
                    <td>订单编号</td>
                    <td>总金额</td>
                    <td>订单状态</td>
                    <td>订单时间</td>
                    <td>用户姓名</td>
                    <td>操作</td>
                </tr>
                <c:forEach items="${orderList}" var="order" varStatus="i">
                    <tr>
                        <td>${i.count}</td>
                        <td>${order.id}</td>
                        <td>${order.money}</td>
                        <td>
                            <c:if test="${order.flag eq 1}">
                                未支付
                            </c:if>
                            <c:if test="${order.flag eq 2}">
                                已支付,待发货
                            </c:if>
                            <c:if test="${order.flag eq 3}">
                                已发货,待收货
                            </c:if>
                            <c:if test="${order.flag eq 4}">
                                已收货,未评价
                            </c:if>
                            <c:if test="${order.flag eq 5}">
                                订单完成
                            </c:if>
                        </td>
                        <td>${order.createtime}</td>
                        <td>${order.username}</td>
                        <td>
                            <c:if test="${order.flag eq 2}">
                                <button type="button" class="btn btn-danger btn-sm"
                                        onclick="sendOrder('${order.id}')">发货
                                </button>
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
    <div>
        <p>
            每页${page.pageSize}条 当前页${page.size}条 ${page.pageNum}/${page.pages}页 总条数${page.total}
        </p>
        <c:if test="${page.isFirstPage==true}"><a>首页</a></c:if>
        <c:if test="${page.isFirstPage==false}">
            <a id="first" onclick="firstPage(${page.firstPage},'${username}',${status})">首页</a>
        </c:if>
        <c:if test="${page.hasPreviousPage==true}">
            <a id="pre" onclick="prePage(${page.prePage},'${username}',${status})">上一页</a>
        </c:if>
        <c:if test="${page.hasPreviousPage==false}"><a>上一页</a></c:if>

        <c:if test="${page.hasNextPage==true}">
            <a id="next" onclick="nextPage(${page.nextPage},'${username}',${status})">下一页</a>
        </c:if>
        <c:if test="${page.hasNextPage==false}"><a>下一页</a></c:if>

        <c:if test="${page.isLastPage==true}"><a>末页</a></c:if>
        <c:if test="${page.isLastPage==false}">
            <a id="last" onclick="lastPage(${page.lastPage},'${username}',${status})">末页</a>
        </c:if>
    </div>
</div>
</body>
</html>